package com.opensource.component.validate;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;

/**
 * @author zhanglong
 * @date 2019-08-3114:44
 */
public class ValidationEntityResult<T> extends
    BaseValidationResult<ValidationEntityResult<T>> {

    private final Map<String, String> errorMsg = new HashMap<>();
    private T data;

    public boolean hasError() {
        return !errorMsg.isEmpty();
    }

    public String errorMsg() {
        return String.join(";", errorMsg.values());
    }

    public T get() {
        return data;
    }

    Map<String, String> getErrorMsg() {
        return errorMsg;
    }

    public void setData(T data) {
        this.data = data;
    }

    /**
     * description 如果是null的话 不额外处理校验结果，如果需要额外处理校验结果需要 {@link Consumer}
     */
    @Override
    public void consumer(Consumer<ValidationEntityResult<T>> validateResultConsumer) {
        validateResultConsumer.accept(this);
    }


}
